package com.beehoo.dcportal.admin.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.beehoo.dcportal.admin.dao.LeaderDao;
import com.beehoo.dcportal.common.base.BaseDao;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.LeaderBean;

public class LeaderDaoImpl extends BaseDao implements LeaderDao {

	private static final Logger logger = Logger.getLogger(LeaderDaoImpl.class);
	
	@Override
	public String addLeader(LeaderBean leaderBean) throws BaseException {
		String id = null;
		try {
			id = (String) sqlMapClient.insert("admin-leader.addLeader", leaderBean);
			logger.info("中心管理-添加领导介绍|#[中心编号：" 
					+ leaderBean.getStreetId()
					+ "],[领导名称：" + leaderBean.getLeaderName()
					+ "],[领导头像：" + leaderBean.getLeaderPhoto()
					+ "],[领导职务：" + leaderBean.getLeaderPosition()
					+ "],[领导职责：" + leaderBean.getLeaderDuty()
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("中心管理-添加领导介绍|#[中心编号：" 
					+ leaderBean.getStreetId()
					+ "],[领导名称：" + leaderBean.getLeaderName()
					+ "],[领导头像：" + leaderBean.getLeaderPhoto()
					+ "],[领导职务：" + leaderBean.getLeaderPosition()
					+ "],[领导职责：" + leaderBean.getLeaderDuty()
					+ "],失败!异常："+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.leader.create.error");
		}
		return id;
	}

	@Override
	public int delLeader(String leaderId) throws BaseException {
		int ret = 0;
		try {
			ret = sqlMapClient.delete("admin-leader.delLeader", leaderId);
			logger.info("中心管理-删除领导介绍|#[领导介绍编号：" + leaderId
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("中心管理-删除领导介绍|#[领导介绍编号：" + leaderId
					+ "],失败!异常："+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.leader.del.error");
		}
		return ret;
	}

	@Override
	public LeaderBean queryLeader(Map<String, Object> paramMap)
			throws BaseException {
		LeaderBean bean = null;
		try {
			bean = (LeaderBean) sqlMapClient.queryForObject("admin-leader.queryLeader", paramMap);
			logger.info("中心管理-查询领导介绍|#[中心编号：" 
					+ paramMap.get("streetId")
					+ "],[领导介绍编号：" + paramMap.get("leaderId")
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("中心管理-查询领导介绍|#[中心编号：" 
					+ paramMap.get("streetId")
					+ "],[领导介绍编号：" + paramMap.get("leaderId")
					+ "],失败!异常："+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.query.create.error");
		}
		return bean;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LeaderBean> queryLeaders(Map<String, Object> paramMap) throws BaseException {
		List<LeaderBean> beanLs = null;
		try {
			beanLs = sqlMapClient.queryForList("admin-leader.queryLeader", paramMap);
			logger.info("中心管理-查询领导介绍|#[中心编号：" + paramMap.get("streetId") + "],成功!");
		} catch (SQLException e) {
			logger.error("中心管理-查询领导介绍|#[中心编号：" + paramMap.get("streetId")
					+ "],失败!异常："+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.query.create.error");
		}
		return beanLs;
	}

	@Override
	public int updateLeader(LeaderBean leaderBean) throws BaseException {
		int ret = 0;
		try {
			ret = sqlMapClient.update("admin-leader.updateLeader", leaderBean);
			logger.info("中心管理-修改领导介绍|#[中心编号：" 
					+ leaderBean.getStreetId()
					+ "],[领导介绍编号：" + leaderBean.getLeaderId()
					+ "],[领导名称：" + leaderBean.getLeaderName()
					+ "],[领导头像：" + leaderBean.getLeaderPhoto()
					+ "],[领导职务：" + leaderBean.getLeaderPosition()
					+ "],[领导职责：" + leaderBean.getLeaderDuty()
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("中心管理-修改领导介绍|#[中心编号：" 
					+ leaderBean.getStreetId()
					+ "],[领导介绍编号：" + leaderBean.getLeaderId()
					+ "],[领导名称：" + leaderBean.getLeaderName()
					+ "],[领导头像：" + leaderBean.getLeaderPhoto()
					+ "],[领导职务：" + leaderBean.getLeaderPosition()
					+ "],[领导职责：" + leaderBean.getLeaderDuty()
					+ "],失败!异常："+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.leader.update.error");
		}
		return ret;
	}

}
